/* GUI CONVERTED from rwdpmt.p (converter v1.76) Wed Nov 28 16:18:09 2001 */
/* rwdpmt.p - DEPARTMENT MAINTENANCE                                    */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                  */
/* All rights reserved worldwide.  This is an unpublished work.         */
/* $Revision: 1.5.1.8 $                                                         */
/*V8:ConvertMode=Maintenance                                            */
/* REVISION: 2.0      LAST MODIFIED: 03/25/87   BY: EMB */
/* REVISION: 4.0      LAST MODIFIED: 03/10/88   BY: RL  *A171**/
/* REVISION: 4.0      LAST MODIFIED: 09/20/88   BY: RL  *C0028*/
/* REVISION: 5.0      LAST MODIFIED: 03/20/89   BY: MLB *A681*/
/* REVISION: 5.0      LAST MODIFIED: 02/22/90   BY: WUG *B581*/
/* REVISION: 6.0      LAST MODIFIED: 11/02/90   BY: emb *D175*/
/* REVISION: 6.0      LAST MODIFIED: 08/02/91   BY: pma *D806*/
/* REVISION: 7.0      LAST MODIFIED: 08/21/91   BY: pma *F003**/
/* REVISION: 7.0      LAST MODIFIED: 11/16/91   BY: pml *F048**/
/* REVISION: 7.0      LAST MODIFIED: 06/16/92   BY: emb *F624**/
/* REVISION: 7.0      LAST MODIFIED: 06/18/92   BY: JJS *F672*(rev only)*/
/* REVISION: 7.0      LAST MODIFIED: 10/14/93   BY: pxd *GG29**/
/* REVISION: 7.3      LAST MODIFIED: 07/31/96 BY: *G2B8* Julie Milligan     */
/* REVISION: 7.3      LAST MODIFIED: 12/31/97 BY: *G2QP* Sandesh Mahagaokar */
/* REVISION: 8.6      LAST MODIFIED: 05/20/98 BY: *K1Q4* Alfred Tan         */
/* REVISION: 9.0      LAST MODIFIED: 04/05/99 BY: *J3D3* G.Latha            */
/* REVISION: 9.1      LAST MODIFIED: 10/01/99 BY: *N014* Jeff Wootton       */
/* REVISION: 9.1      LAST MODIFIED: 01/19/99 BY: *N077* Vijaya Pakala      */
/* REVISION: 9.1      LAST MODIFIED: 02/12/00 BY: *N07Z* Vijaya Pakala      */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00 BY: *N08T* Annasaheb Rahane */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00 BY: *N0KP* myb                */
/* Old ECO marker removed, but no ECO header exists *F0PN*                    */
/* $Revision: 1.5.1.8 $    BY: Anil Sudhakaran       DATE: 11/28/01  ECO: *M1FH*  */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

/* DISPLAY TITLE */
{mfdtitle.i "b+ "}

/* ********** Begin Translatable Strings Definitions ********* */

&SCOPED-DEFINE rwdpmt_p_1 "Default Sub-Account"
/* MaxLen: 24 Comment: */

&SCOPED-DEFINE rwdpmt_p_2 "Default Cost Center"
/* MaxLen: 24 Comment: */

&SCOPED-DEFINE rwdpmt_p_3 "Override"
/* MaxLen: 14 Comment: */

/* ********** End Translatable Strings Definitions ********* */

define variable del-yn like mfc_logical initial no.
define variable valid_acct like mfc_logical no-undo.

define variable default_sub as character no-undo
   initial "" label {&rwdpmt_p_1}.
define variable default_cc as character format "x(4)" no-undo
   initial "" label {&rwdpmt_p_2}.
define variable override_sub like mfc_logical no-undo
   initial no label {&rwdpmt_p_3}.
define variable override_cc like mfc_logical no-undo
   initial no label {&rwdpmt_p_3}.

{gprunpdf.i "gpglvpl" "p"}

/* Variable added to perform delete during CIM.
 * Record is deleted only when the value of this variable
 * Is set to "X" */
define variable batchdelete as character format "x(1)" no-undo.

/* DISPLAY SELECTION FORM */

/*GUI preprocessor Frame A define */
&SCOPED-DEFINE PP_FRAME_NAME A

FORM /*GUI*/ 
   
 RECT-FRAME       AT ROW 1 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1 COLUMN 3 NO-LABEL VIEW-AS TEXT SIZE-PIXELS 1 BY 1
 SKIP(.1)  /*GUI*/
dpt_dept       colon 30
   skip(1)
   default_sub    colon 30
   override_sub   colon 55
   default_cc     colon 30
   override_cc    colon 55
   skip(1)
   dpt_desc       colon 30 skip(1)
   dpt_lbr_cap    colon 30 skip(1)
   dpt_cop_acct   colon 30
   dpt_cop_sub    no-label
   dpt_cop_cc     no-label
   dpt_lbr_acct   colon 30
   dpt_lbr_sub    no-label
   dpt_lbr_cc     no-label
   dpt_bdn_acct   colon 30
   dpt_bdn_sub    no-label
   dpt_bdn_cc     no-label
   dpt_lvar_acc   colon 30

   dpt_lvar_sub   no-label
   dpt_lvar_cc    no-label
   dpt_lvrr_acc   colon 30
   dpt_lvrr_sub   no-label
   dpt_lvrr_cc    no-label
   dpt_bvar_acc   colon 30
   dpt_bvar_sub   no-label
   dpt_bvar_cc    no-label
   dpt_bvrr_acc   colon 30
   dpt_bvrr_sub   no-label
   dpt_bvrr_cc    no-label

 SKIP(.4)  /*GUI*/
with frame a side-labels width 80 attr-space NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-a-title AS CHARACTER INITIAL "".
 RECT-FRAME-LABEL:SCREEN-VALUE in frame a = F-a-title.
 RECT-FRAME-LABEL:HIDDEN in frame a = yes.
 RECT-FRAME:HEIGHT-PIXELS in frame a =
  FRAME a:HEIGHT-PIXELS - RECT-FRAME:Y in frame a - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME a = FRAME a:WIDTH-CHARS - .5.  /*GUI*/

/*GUI preprocessor Frame A undefine */
&UNDEFINE PP_FRAME_NAME



/* SET EXTERNAL LABELS */
setFrameLabels(frame a:handle).

/* DISPLAY */
view frame a.
mainloop:
repeat with frame a:
/*GUI*/ if global-beam-me-up then undo, leave.


   /* Initialize delete flag before each display of frame */
   batchdelete = "".

   assign
      override_sub = no
      override_cc  = no.

   prompt-for dpt_dept
   /* Prompt for the delete variable in the key frame at the
    * End of the key field/s only when batchrun is set to yes */
   batchdelete no-label when (batchrun)
   editing:

      /* FIND NEXT/PREVIOUS RECORD */
      {mfnp.i dpt_mstr dpt_dept dpt_dept dpt_dept dpt_dept dpt_dept}

      /* IF DEPARTMENT FIELD ENTERED, */
      /* FIND RECORD SO EXISTING DATA CAN BE DISPLAYED */
      if recno = ? then
      for first dpt_mstr using dpt_dept no-lock:
      recno = recid(dpt_mstr).
      end.

      if recno <> ? then
      display
         dpt_dept
         default_sub override_sub
         default_cc override_cc
         dpt_desc
         dpt_lbr_cap
         dpt_cop_acct
         dpt_cop_sub
         dpt_cop_cc
         dpt_lbr_acct
         dpt_lbr_sub
         dpt_lbr_cc
         dpt_bdn_acct
         dpt_bdn_sub
         dpt_bdn_cc
         dpt_lvar_acc
         dpt_lvar_sub
         dpt_lvar_cc
         dpt_lvrr_acc
         dpt_lvrr_sub
         dpt_lvrr_cc
         dpt_bvar_acc
         dpt_bvar_sub
         dpt_bvar_cc
         dpt_bvrr_acc
         dpt_bvrr_sub
         dpt_bvrr_cc.

   end.
/*GUI*/ if global-beam-me-up then undo, leave.


   if input dpt_dept = " " then do:
      /* BLANK NOT ALLOWED */
      {pxmsg.i &MSGNUM=40 &ERRORLEVEL=3}
      undo mainloop.
   end.

   display default_sub override_sub default_cc override_cc.
   defaultloop:
   do with frame a on error undo, retry:
/*GUI*/ if global-beam-me-up then undo, leave.

      set default_sub override_sub default_cc override_cc.

      /* VALIDATE SUB-ACCOUNT */
      if override_sub then do:
         if not ({gpglsub.v default_sub}) then do:
            next-prompt default_sub with frame a.
            /* INVALID SUB-ACCOUNT CODE */
            {pxmsg.i &MSGNUM=3131 &ERRORLEVEL=3}
            undo defaultloop, retry defaultloop.
         end.
      end.
      /* VALIDATE COST CENTER */
      if override_cc then do:
         if not ({gpglcc.v default_cc}) then do:
            next-prompt default_cc with frame a.
            /* INVALID COST CENTER */
            {pxmsg.i &MSGNUM=3057 &ERRORLEVEL=3}
            undo defaultloop, retry defaultloop.
         end.
      end.
   end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* DEFAULTLOOP: DO: */

   /* ADD/MOD/DELETE  */
   find dpt_mstr using dpt_dept no-error.
   if not available dpt_mstr
   then do:
      if input dpt_dept = "" then do:
         /* BLANK NOT ALLOWED */
         {pxmsg.i &MSGNUM=40 &ERRORLEVEL=3}
         next-prompt dpt_dept with frame a.
         undo.
      end.

      /* ADDING NEW RECORD */
      {pxmsg.i &MSGNUM=1 &ERRORLEVEL=1}
      create dpt_mstr.
      assign dpt_dept.
      find first gl_ctrl no-lock no-error.
      if available gl_ctrl then
      assign
         dpt_cop_acct = gl_cop_acct
         dpt_lbr_acct = gl_lbr_acct
         dpt_bdn_acct = gl_bdn_acct
         dpt_lvar_acc = gl_lvar_acct
         dpt_lvrr_acc = gl_lvrr_acct
         dpt_bvar_acc = gl_bvar_acct
         dpt_bvrr_acc = gl_bvrr_acct.

      if override_sub then
      assign
         dpt_cop_sub   = default_sub
         dpt_lbr_sub   = default_sub
         dpt_bdn_sub   = default_sub
         dpt_lvar_sub  = default_sub
         dpt_lvrr_sub  = default_sub
         dpt_bvar_sub  = default_sub
         dpt_bvrr_sub  = default_sub.
      else
         if available gl_ctrl then
      assign
         dpt_cop_sub   = gl_cop_sub
         dpt_lbr_sub   = gl_lbr_sub
         dpt_bdn_sub   = gl_bdn_sub
         dpt_lvar_sub  = gl_lvar_sub
         dpt_lvrr_sub  = gl_lvrr_sub
         dpt_bvar_sub  = gl_bvar_sub
         dpt_bvrr_sub  = gl_bvrr_sub.
      if override_cc then
      assign
         dpt_cop_cc    = default_cc
         dpt_lbr_cc    = default_cc
         dpt_bdn_cc    = default_cc
         dpt_lvar_cc   = default_cc
         dpt_lvrr_cc   = default_cc
         dpt_bvar_cc   = default_cc
         dpt_bvrr_cc   = default_cc.
      else
         if available gl_ctrl then
      assign
         dpt_cop_cc    = gl_cop_cc
         dpt_lbr_cc    = gl_lbr_cc
         dpt_bdn_cc    = gl_bdn_cc
         dpt_lvar_cc   = gl_lvar_cc
         dpt_lvrr_cc   = gl_lvrr_cc
         dpt_bvar_cc   = gl_bvar_cc
         dpt_bvrr_cc   = gl_bvrr_cc.

   end.

   /* STORE MODIFY DATE AND USERID */
   dpt_mod_date = today.
   dpt_userid = global_userid.

   recno = recid(dpt_mstr).

   display
      dpt_dept
      dpt_desc
      dpt_lbr_cap
      dpt_lbr_acct
      dpt_bdn_acct
      dpt_lvar_acc
      dpt_cop_acct
      dpt_lvrr_acc
      dpt_bvar_acc
      dpt_bvrr_acc.

   if override_sub then
   display
      default_sub @ dpt_cop_sub
      default_sub @ dpt_lbr_sub
      default_sub @ dpt_bdn_sub
      default_sub @ dpt_lvar_sub
      default_sub @ dpt_lvrr_sub
      default_sub @ dpt_bvar_sub
      default_sub @ dpt_bvrr_sub.
   else
   display
      dpt_cop_sub
      dpt_lbr_sub
      dpt_bdn_sub
      dpt_lvar_sub
      dpt_lvrr_sub
      dpt_bvar_sub
      dpt_bvrr_sub.
   if override_cc then
   display
      default_cc @ dpt_cop_cc
      default_cc @ dpt_lbr_cc
      default_cc @ dpt_bdn_cc
      default_cc @ dpt_lvar_cc
      default_cc @ dpt_lvrr_cc
      default_cc @ dpt_bvar_cc
      default_cc @ dpt_bvrr_cc.
   else
   display
      dpt_cop_cc
      dpt_lbr_cc
      dpt_bdn_cc
      dpt_lvar_cc
      dpt_lvrr_cc
      dpt_bvar_cc
      dpt_bvrr_cc.

   ststatus = stline[2].
   status input ststatus.

   do on error undo, retry:
/*GUI*/ if global-beam-me-up then undo, leave.


      del-yn = no.

      set
         dpt_desc
         dpt_lbr_cap
         dpt_cop_acct
         dpt_cop_sub
         dpt_cop_cc
         dpt_lbr_acct
         dpt_lbr_sub
         dpt_lbr_cc
         dpt_bdn_acct
         dpt_bdn_sub
         dpt_bdn_cc
         dpt_lvar_acc
         dpt_lvar_sub
         dpt_lvar_cc
         dpt_lvrr_acc
         dpt_lvrr_sub
         dpt_lvrr_cc
         dpt_bvar_acc
         dpt_bvar_sub
         dpt_bvar_cc
         dpt_bvrr_acc
         dpt_bvrr_sub
         dpt_bvrr_cc
         go-on ("F5" "CTRL-D").

      /* DELETE */
      if lastkey = keycode("F5")
         or lastkey = keycode("CTRL-D")
      /* Delete to be executed if batchdelete is set to "x" */
      or input batchdelete = "x":U
      then do:
         del-yn = yes.
         /* PLEASE CONFIRM DELETE */
         {pxmsg.i &MSGNUM=11 &ERRORLEVEL=1 &CONFIRM=del-yn}
         if del-yn = no then undo, retry.

         if can-find(first emp_mstr where emp_dept = dpt_dept)
         then do:

            /*DELETE NOT ALLOWED, OUTSTANDING EMPLOYEE(S) */
            {pxmsg.i &MSGNUM=1458 &ERRORLEVEL=4}

            undo, retry.
         end.

         find first wc_mstr where wc_dept = dpt_dept
         no-lock no-error.
         if available wc_mstr then do:
            /* DELETE NOT ALLOWED. WORK CENTER(S) EXIST */
            {pxmsg.i &MSGNUM=538 &ERRORLEVEL=3}
            /* Delete not allowed work center(s) exist*/
            undo, retry.
         end.

         delete dpt_mstr.
         clear frame a.
/*GUI*/ RECT-FRAME-LABEL:SCREEN-VALUE in frame a = F-a-title.
         del-yn = no.
         next mainloop.
      end.

      /* TO AVOID PROGRESS ERROR "NO AC_MSTR  RECORD   */
      /* IS AVAILABLE" WHEN ALLOCATION CODE IS ENTERED */
      /* INSTEAD OF ACCOUNT CODES                      */

      /* CHANGED dpt_lbr_cc TO dpt_bdn_cc IN FOLLOWING */

      /* ACCT/SUB/CC VALIDATION */
      run ip-validate
         (input dpt_cop_acct,
         input dpt_cop_sub,
         input dpt_cop_cc).

      if valid_acct = no then do:
         next-prompt dpt_cop_acct with frame a.
         undo, retry.
      end.

      run ip-validate
         (input dpt_lbr_acct,
         input dpt_lbr_sub,
         input dpt_lbr_cc).

      if valid_acct = no then do:
         next-prompt dpt_lbr_acct with frame a.
         undo, retry.
      end.

      run ip-validate
         (input dpt_bdn_acct,
         input dpt_bdn_sub,
         input dpt_bdn_cc).

      if valid_acct = no then do:
         next-prompt dpt_bdn_acct with frame a.
         undo, retry.
      end.

      run ip-validate
         (input dpt_lvar_acc,
         input dpt_lvar_sub,
         input dpt_lvar_cc).

      if valid_acct = no then do:
         next-prompt dpt_lvar_acc with frame a.
         undo, retry.
      end.

      run ip-validate
         (input dpt_lvrr_acc,
         input dpt_lvrr_sub,
         input dpt_lvrr_cc).

      if valid_acct = no then do:
         next-prompt dpt_lvrr_acc with frame a.
         undo, retry.
      end.

      run ip-validate
         (input dpt_bvar_acc,
         input dpt_bvar_sub,
         input dpt_bvar_cc).

      if valid_acct = no then do:
         next-prompt dpt_bvar_acc with frame a.
         undo, retry.
      end.

      run ip-validate
         (input dpt_bvrr_acc,
         input dpt_bvrr_sub,
         input dpt_bvrr_cc).

      if valid_acct = no then do:
         next-prompt dpt_bvrr_acc with frame a.
         undo, retry.
      end.

   end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* DO ON ERROR UNDO */

end. /* MAINLOOP */
status input.

PROCEDURE ip-validate:
   define input parameter ip-acct as character.
   define input parameter ip-sub  as character.
   define input parameter ip-cc   as character.

   /* INITIALIZE SETTINGS */
   {gprunp.i "gpglvpl" "p" "initialize"}
   /* SET PROJECT VERIFICATION TO NO */
   {gprunp.i "gpglvpl" "p" "set_proj_ver" "(input false)"}
   /* ACCT/SUB/CC VALIDATION */
   {gprunp.i "gpglvpl" "p" "validate_fullcode"
      "(input ip-acct,
        input ip-sub,
        input ip-cc,
        input """",
        output valid_acct)"}

END PROCEDURE.  /* ip-validate */
